package com.wtwd.campus.netty;


import com.wtwd.campus.encryptnetty.EncryptMessageEncoder;
import com.wtwd.campus.utils.AESUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// MessageToByteEncoder<I> 中的泛型表示原数据类型
public class MessageEncoder extends MessageToByteEncoder<Object> {


    private final static Logger logger = LoggerFactory.getLogger(MessageEncoder.class);

    @Override
    public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out)
            throws Exception {
        logger.info("channel id:{},发送消息={}", ctx.channel().id(), msg.toString());
        out.writeBytes(msg.toString().getBytes("utf-8"));
    }
}
